/**
 * Due to my laziness Flair is currently dependant on jQuery. However, the jQuery
 * dependancies are encapsulated in the code to wrapper functions of Flair so
 * that they can be replaced with out having to search through the code base.
 * Until jQuery dependant functions have been replaced, die if jQuery hasn't been
 * included already.
 */
if(!jQuery)
	throw "Flair is dependant on jQuery. Please include jQuery before Flair.";
	
	
var Flair = {
	/**
	 * Path to Flair source directory
	 */
	pathToFlair: ''
	/**
	 * List of files already required
	 */
	,required: new Array() 
	/**
	 * require (once) a javascript file
	 * @param {path} path & file name
	 * @param {abs} use absolute path instead of concating with pathToFlair
	 */
	,require: function (path, abs) {
		if(this.required.indexOf(path) > -1)
			return;

		this.required.push(path);
			
		if(!abs)
			path = this.pathToFlair + path;
			
		//$.getScript(this.pathToFlair + path);	
		document.write("<script type='text/javascript' src='"+path+"'></script>");
		Flair.log('required:', path);
	}
	
	/**
	 * Test if object is a function
	 * @param {object} to test
	 * @return boolen
	 */
	,isFunction: function (obj) {
		return $.isFunction(obj);
	}
	
	/**
	 * Create a new object from baseObj extended by extObj
	 * @param {baseObj} the base object (overridden by extend)
	 * @param {extObj} the extending object (overrides base)
	 * @return {Object} new object
	 */
	,extend: function (baseObj, extObj) {
		if(!extObj) 
			return baseObj;
		// clone base
		var bIsFunc = this.isFunction(baseObj);
		var eIsFunc = this.isFunction(extObj);
		
		var eattribs = eIsFunc ? new extObj() : extObj;
		
		var newObj;
		if(bIsFunc) {
			newObj = function () {}
			newObj.prototype = new baseObj();
		} else {
			newObj = new Object();
			for(var i in baseObj)
				newObj[i] = baseObj[i];
		}
		Flair.log(newObj, newObj.prototype);
		// extend newObj
		for(var i in eattribs){
			Flair.log('eattrib: ', i);
			if(eattribs[i] != undefined)
				if(bIsFunc)
					newObj.prototype[i] = eattribs[i];
				else
					newObj[i] = eattribs[i];
		}
		// done
		Flair.log(bIsFunc, newObj);
		return newObj;
	}
	/**
	 * Shortcut to air introspector logger
	 * @param {params}
	 */
	,log: function () {
		air.Introspector.Console.log.call(air.Introspector.Console.log, arguments);
	}
	
	,Controllers: {}
};